package todomanager.View;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;

/**
 * Represents the clock displayed at the bottom-left of the main frame
 * @author Tolga
 *
 */
public class Clock extends JLabel {
    javax.swing.Timer m_t;

    public Clock() {
        setFont(new Font("sansserif", Font.PLAIN, 12));

        //Create a 1-second timer.
        m_t = new javax.swing.Timer(1000, new ClockTickAction());
        m_t.start();  // Start the timer
    }

    private class ClockTickAction implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            //Get the current time and set the Text
            Calendar now = Calendar.getInstance();
            int year = now.get(Calendar.YEAR);
            int mon = now.get(Calendar.MONTH) + 1;
            int day = now.get(Calendar.DAY_OF_MONTH);
            int hour = now.get(Calendar.HOUR_OF_DAY);
            int min = now.get(Calendar.MINUTE);
            int sec = now.get(Calendar.SECOND);
            setText("" + year + "-" + mon + "-" + day + " " + hour + ":" + min + ":" + sec);
        }
    }
}